package com.mzlalal.donate.controller;

import com.mzlalal.donate.model.comm.Results;
import com.mzlalal.donate.service.IndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @description:
 * @author: Mzlalal
 * @date: 2019/12/27 15:52
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    IndexService service;

    /**
     * 获取总数
     * @return
     */
    @RequestMapping("/totalAmount")
    public Results getTotalAmount() {
        BigDecimal bigDecimal = null;
        try {
            bigDecimal = service.getTotalAmount();
        } catch (Exception e) {
            log.error("", e);
            Results.FAIL("当前服务繁忙!");
        }
        return Results.OK("获取总数成功!", bigDecimal);
    }

    /**
     * 获取最近七天捐款情况
     * @return
     */
    @RequestMapping("/recentSevenDonate")
    public Results getRecentSevenDonate() {
        List<Map<String, Object>> data = null;
        try {
            data = service.getRecentSevenDonate();
        } catch (Exception e) {
            log.error("", e);
            Results.FAIL("当前服务繁忙!");
        }
        return Results.OK("获取获取最近七天捐款情况成功!", data);
    }
}
